package br.org.espmessenger.modelo;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;

@Entity
public class Grupo implements Serializable {
	private static final long serialVersionUID = 1L;

	private int id;
	private String nome;
	private Usuario owner;
	private Collection<Usuario> adicionados;
	
	@Id @GeneratedValue(generator="gengrupo")
	@SequenceGenerator(name="gengrupo", sequenceName="grupo_id_seq", allocationSize=1, initialValue=1)
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getNome() {
		return nome;
	}
	public void setNome(String nome) {
		this.nome = nome;
	}
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="id_usuario")
	public Usuario getOwner() {
		return owner;
	}
	public void setOwner(Usuario owner) {
		this.owner = owner;
	}
	@ManyToMany
	@JoinTable(name="usuarios_agrupados",
			joinColumns=@JoinColumn(name="id_grupo"),
			inverseJoinColumns=@JoinColumn(name="id_usuario"))
	public Collection<Usuario> getAdicionados() {
		return adicionados;
	}
	public void setAdicionados(Collection<Usuario> adicionados) {
		this.adicionados = adicionados;
	}
	public static long getSerialVersionUID() {
		return serialVersionUID;
	}
}
